package FigureDogs.anews24;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebSettings.LayoutAlgorithm;

public class NewsActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_news);
		
		new parser().execute();

	}
	
	class parser extends AsyncTask<Void, Void, Void> {
        Document doc;
        WebView m1WebView;

		@Override
		protected Void doInBackground(Void... arg0) { 
		        Document doc = null;
		        try {
		            doc = Jsoup.connect("http://www.anews24.it/category/news24/").get();
		        } catch (IOException e) {
		            // TODO Auto-generated catch block
		            e.printStackTrace();
		        }
		        
		        Element featured =doc.getElementById("featured");
		        m1WebView = (WebView) findViewById(R.id.WebViewNews);
		        m1WebView.setWebViewClient(new NewsClient());
		        m1WebView.setScrollbarFadingEnabled(true);
		        WebSettings webSettings = m1WebView.getSettings();
		        m1WebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
		        String content=featured.toString();
		        m1WebView.loadDataWithBaseURL("",content, "text/html", "utf-8",null);
		        
		        
		        
		        
		        
				return null;
		}
	}
	private class NewsClient extends WebViewClient {
		
	    public boolean shouldOverrideUrlLoading(WebView view, String url) {
	    	System.out.println("URL: " + url);
	    	view.loadUrl("javascript:changeLocation('" + url + "')");
	        return true;
	    }
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.news, menu);
		return true;
	}

}
